/**
 * 
 */
package com.ms.service.module.baccarat;

import com.ms.service.module.zone.command.BasicDebugCommand;
import com.ms.service.module.zone.command.CommandHelper;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.game.time.TimeConstants;

/**
 * 百家樂測試指令
 * 
 * @author TW15010
 */
public class BacrCommand extends BasicDebugCommand {
	public static final int CMD_ADD_CARD = 1;
	public static final int CMD_NEXT_STEP = 2;
	public static final int CMD_START = 3;
	public static final int CMD_GET_RESULT = 4;

	private CommandHelper helper = new CommandHelper(getName());

	public BacrCommand() {
		helper.addParam(CMD_ADD_CARD, "add", "add card to card shoe, [card index 101,102,103,....]");
		helper.addParam(CMD_NEXT_STEP, "next", "goto next step, no param.");
		helper.addParam(CMD_START, "start", "start bacarrat game.");
		helper.addParam(CMD_GET_RESULT, "result", "get current result.");
	}

	/**
	 * 測試的 code 可以寫在這裡
	 */
	@Override
	public String execute() {
		int cmdIndex = helper.getCommandIndex(commandValue);

		BasicZoneModule zoneModule = getModule();
		BacrGameModule module = null;
		if (zoneModule instanceof BacrGameModule) {
			module = (BacrGameModule) zoneModule;
		} else {
			return "this is not bacr game module.";
		}
		BacrGameCore core = module.getProc().getCore(getPlayer().getGuid());

		switch (cmdIndex) {
		case CMD_ADD_CARD: {
			String cmdName = commandValue[1];
			String cardListStr = command.replaceAll(getName() + "\\s+" + cmdName, "");

			if (core != null) {
				core.insertCardToShoe(cardListStr);
			}
			break;
		} // case CMD_ADD_CARD: {

		case CMD_NEXT_STEP: {
			if (core != null) {
				core.gotoNextStep();
			}
			break;
		} // case CMD_ADD_CARD: {

		case CMD_START: {
			BacrAPI.sendStartGameNotify(60 * TimeConstants.MILLI_SECOND_PRE_SECOND);
			break;
		}

		case CMD_GET_RESULT: {
			BacrGameResult result = core.getCurrentGameResult();
			return result.toString();
		}
		}

		return "ok";
	}

	@Override
	public String getName() {
		return "bacr";
	}

	@Override
	public String getDescription() {
		return getShortDescription();
	}

	@Override
	public String getShortDescription() {
		return "bacarrat commands.";
	}
}
